var matrixTestCase = {};

var Matrix = it.koutifaris._tetris.Matrix;

matrixTestCase.getTestCaseName = function() {
	return "Matrix Test";
};

matrixTestCase.testCoords = function() {
	var matrix = new Matrix(10);
	var x = 8;
	var y = 2;
	var i = matrix.xy2i(x, y);

	assertEquals(x, matrix.i2x(i));
	assertEquals(y, matrix.i2y(i));
};

matrixTestCase.testEquals = function() {
	var m1 = [ 1, 2, 3 ];
	var m2 = [ 1, 2, 3 ];

	assertTrue(new Matrix(2, m1).equals(new Matrix(2, m2)));
};

matrixTestCase.testNotEqualsDifferentSize = function() {
	var m1 = [ 1, 2, 3 ];
	var m2 = [ 1, 2, 3 ];

	assertFalse(new Matrix(3, m1).equals(new Matrix(2, m2)));
};

matrixTestCase.testNotEquals = function() {
	var m1 = [ 1, 2, 3 ];
	var m2 = [ 1, 2, 4 ];

	assertFalse(new Matrix(1, m1).equals(new Matrix(1, m2)));
};

matrixTestCase.testSwap = function() {
	var actual = new Matrix(3, [ 1, 2, 3, ]);
	var expected = new Matrix(3, [ 1, 3, 2 ]);

	actual.swap(1, 2);

	assertTrue(expected.equals(actual));
};

matrixTestCase.testSwapColumns = function() {
	var actual = new Matrix(3, [ 1, 2, 3, 4, 5, 6 ]);
	var expected = new Matrix(3, [ 3, 2, 1, 6, 5, 4 ]);

	actual.swapColumns();

	assertTrue(expected.equals(actual));
};

matrixTestCase.testSwapColumnsEvenSize = function() {
	var actual = new Matrix(2, [ 1, 2, 3, 4, 5, 6 ]);
	var expected = new Matrix(2, [ 2, 1, 4, 3, 6, 5 ]);

	actual.swapColumns();

	assertTrue(expected.equals(actual));
};

matrixTestCase.testSwapRows = function() {
	var actual = new Matrix(3, [ 1, 2, 3, 4, 5, 6 ]);
	var expected = new Matrix(3, [ 4, 5, 6, 1, 2, 3 ]);

	actual.swapRows();

	assertTrue(expected.equals(actual));
};

matrixTestCase.testTranspose = function() {
	var actual = new Matrix(3, [ 1, 2, 3, 4, 5, 6 ]);
	var expected = new Matrix(2, [ 1, 4, 2, 5, 3, 6 ]);

	actual.transpose();

	assertTrue(expected.equals(actual));
};

matrixTestCase.testRotateRight = function() {
	var actual = new Matrix(3, [ 1, 2, 3, 4, 5, 6 ]);
	var expected = new Matrix(2, [ 4, 1, 5, 2, 6, 3 ]);

	actual.rotate(+1);

	assertTrue(expected.equals(actual));
};

matrixTestCase.testRotateLeft = function() {
	var actual = new Matrix(3, [ 1, 2, 3, 4, 5, 6 ]);
	var expected = new Matrix(2, [ 3, 6, 2, 5, 1, 4 ]);

	actual.rotate(-1);

	assertTrue(expected.equals(actual));
};

matrixTestCase.testRotate0 = function() {
	var actual = new Matrix(2, [ 1, 0, 0, 0 ]);
	var expected = new Matrix(2, [ 1, 0, 0, 0 ]);

	actual.rotate(0);

	assertTrue(expected.equals(actual));
};

matrixTestCase.testRotateRight1 = function() {
	var actual = new Matrix(2, [ 1, 0, 0, 0 ]);
	var expected = new Matrix(2, [ 0, 1, 0, 0 ]);

	actual.rotate(1);

	assertTrue(expected.equals(actual));
};

matrixTestCase.testRotateRight2 = function() {
	var actual = new Matrix(2, [ 1, 0, 0, 0 ]);
	var expected = new Matrix(2, [ 0, 0, 0, 1 ]);

	actual.rotate(2);

	assertTrue(expected.equals(actual));
};

matrixTestCase.testRotateRight3 = function() {
	var actual = new Matrix(2, [ 1, 0, 0, 0 ]);
	var expected = new Matrix(2, [ 0, 0, 1, 0 ]);

	actual.rotate(3);

	assertTrue(expected.equals(actual));
};

matrixTestCase.testRotateRight4 = function() {
	var actual = new Matrix(2, [ 1, 0, 0, 0 ]);
	var expected = new Matrix(2, [ 1, 0, 0, 0 ]);

	actual.rotate(4);

	assertTrue(expected.equals(actual));
};

matrixTestCase.testRotateLeft2 = function() {
	var actual = new Matrix(2, [ 1, 0, 0, 0 ]);
	var expected = new Matrix(2, [ 0, 0, 0, 1 ]);

	actual.rotate(-2);

	assertTrue(expected.equals(actual));
};

matrixTestCase.testClone = function() {
	var actual = new Matrix(3, [ 1, 2, 3, 4, 5, 6 ]);
	var expected = new Matrix(3, [ 1, 2, 3, 4, 5, 6 ]);

	assertTrue(expected.equals(actual.clone()));
};